<template>
  <div class="app-container">
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-delete" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="hotelList">
      <el-table-column width="55" align="center" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="昵称" align="center" prop="nickName" />
      <el-table-column label="邮箱地址" align="center" prop="email" />
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listUser } from "@/api/system/user";
import { uploadImage } from "@/api/common";
export default {
  name: "Hotel",
  data () {
    return {
      title: '',
      // 遮罩层
      loading: true,
      open: false,
      // 选中数组
      ids: [],
      form: {},
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户数据
      hotelList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      rules: {
        name: [
          { required: true, message: "酒店名称不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "酒店地址不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "酒店预约状态不能为空", trigger: "blur" }
        ],
      },
      imageUrl: "",
    };
  },
  created () {
    this.getList();
  },
  computed: {},
  methods: {


    handleAdd (row) {
      this.reset();
      this.open = true;
      this.title = "添加酒店";
    },
    /** 查询酒店列表 */
    getList () {
      this.loading = true;
      listUser(this.queryParams).then((response) => {
        this.hotelList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => {
        return item.id;
      });
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除酒店信息？")
        .then(function () {
          return DelHotel(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const id = row.id || this.ids;
      GetDetail(id).then((response) => {
        this.form.id = response.data.id
        this.form.name = response.data.hotelName
        this.form.address = response.data.fullAddress
        this.form.longitude = response.data.longitude
        this.form.latitude = response.data.latitude
        this.form.status = response.data.status == 1 ? true : false
        this.form.indexImg = response.data.indexImg
        this.form.rule = response.data.rule
        this.imageUrl = response.data.indexImg;
        this.open = true;
        this.title = "修改酒店信息";
      });
    },
    /** 提交按钮 */
    submitForm () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.status = this.form.status == true ? 1 : 2
          if (this.form.id != null) {
            UpdateHotel(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            AddHotel(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        name: undefined,
        address: undefined,
        latitude: undefined,
        longitude: undefined,
        status: false
      };
      this.imageUrl = "";
      this.resetForm("form");
    },
  },
};
</script>
<style scoped lang="scss">
.modal-wrap {
  ::v-deep .el-dialog__body {
    height: 600px;
    overflow-y: scroll;
  }
}

.avatar-uploader {
  ::v-deep .el-upload {
    width: 100px;
    height: 100px;
    border: 1px dotted #eee;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .avatar-uploader-icon {
    font-size: 24px;
  }
}

.banner-img {
  width: 100px;
  height: 100px;
  // margin-left: 20px;
}

.editBox {
  display: flex;
  justify-content: space-between;
}
</style>
